package com.masq.agencija.pages;

import java.util.LinkedList;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.masq.agencija.beans.AgentB;
import com.masq.agencija.interfaces.Rent;
import com.masq.agencija.interfaces.Agent;
import com.masq.agencija.interfaces.AuxClient;
import com.masq.agencija.pages.Login;
import com.masq.agencija.service.Agenti;

public class UnosAgenta {
	@Property
	@Persist
	private Agent agent;

	@Inject
	private Agenti agenti;

	@SetupRender
	public void createObject() {
		agent = new AgentB();
		agent.setIznajmljivanje(new LinkedList<Rent>());
	}

	void onSuccess() {
		agenti.save(agent);
	}
	
	@SessionState
	private AuxClient user;

	private boolean userExists;
	
	public AuxClient getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}
}
